#include <iostream>
using namespace std;
#include<stdio.h>
#include<stdlib.h>
#include "LinkNode.h"
#include <vector>

bool contain(vector<int> A,int i){
	vector<int>::iterator it;
	for(it=A.begin();it!=A.end();it++){
		if (*it==i){
			return true;
		}
	}
	return false;
}


int main()
{
	LinkList *L1,*L2;
	ElemType A[10]={1,2,3,4,5,6,7,8,9,10};
	InitList(L1);
	CreateListR(L1,A,10);
	printf("输入A中的数据元素: \n");
	DispList(L1);
	
	
	ElemType B[8]={2,0,0,5,2,0,6,2};
	InitList(L2);
	CreateListR(L2,B,8);
	printf("输入B中的数据元素：\n");
	DispList(L2);
	vector<int> vect;
	for (int i = 0 ;i < 8 ; i++){
		if (!contain(vect,B[i])){
			vect.push_back(B[i]);
		}
	}
	vector<int>::iterator it;
	printf("转纯集合，所以B中的数据元素为：\n");
	ElemType C[vect.size()];
	int i = 0;
	for(it=vect.begin();it!=vect.end();it++){
		int j = *it;
		C[i] = j;
		i++;
	}
	InitList(L2);
	CreateListR(L2,C,vect.size());
	DispList(L2);
	
	printf("\n");
	
	LNode *p2 = L2->next;
	
	while(p2!=NULL){
		if (LocateElem(L1,p2->data)==0){
			ListInsert(L1,1,p2->data);
		}
		p2 = p2->next;
	}
	
	printf("求并集：A=A∪B: \n");
	DispList(L1);
	printf("\n");
	return 0;
	
}


